<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/11/15
 * Time: 10:16
 */

namespace app\common\model;


use think\Exception;

class GoodsImages extends BaseModel
{
    protected $deleteTime = false;

    /**
     * 获取商品的图片列表
     * @param $goods_id
     * @param $type
     * @return array|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getList($goods_id, $type) {
        return self::where('goods_id', '=', $goods_id)->where('type', '=', $type)->order('sort asc, id desc')->select();
    }

    /**
     * 添加商品图片
     * @param $goods_id
     * @param $type
     * @param $path
     */
    public static function createGoodsImage($goods_id, $type, $path) {
        self::create([
            'goods_id' => $goods_id,
            'image' => $path,
            'type' =>$type
        ]);
    }

    /**
     * 修改产品图片的排序
     * @param $id
     * @param $sort
     * @return \think\response\Json
     */
    public static function saveImgSort($id, $sort) {
        try {
            self::where('id', '=', $id)->update(['sort' => $sort]);
            return return_data('修改成功！');
        } catch (Exception $e) {
            return return_data($e->getMessage(), 1);
        }

    }
}